<link href="/css/login/login.css" media="screen" rel="stylesheet" type="text/css"/>
<link href="/css/global/form.css" media="screen" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="/script/jshash/sha512-min.js"></script>
<script type="text/javascript" src="/script/login/check.js"></script>
<script type="text/javascript" src="/script/global/form.js"></script>
<script type="text/javascript">
	function submit(){
		$("#form_login #button_signup").attr("href", "javascript:void(0)");
		var method = $("#form_login #login_method").val();
		var username = $("#form_login #input_username").val();
		var password = $("#form_login #input_password").val();
		if ((method == "mobile" && !isValidMobile(username)) || (method == "fidocard" && !isValidFidocard(username))){		
			showError("您输入的" + (method == "mobile" ? "手机号" : "Fido卡号") + "不合法，请再次输入。");
			$("#form_login #button_signup").attr("href", "javascript:submit()");
			return;
		}
		if (!isValidPassword(password)){
			showError("您输入的密码不合法，请再次输入。");
			$("#form_login #button_signup").attr("href", "javascript:submit()");
			return;
		}	
		$.post("/login/getLoginCode", function(data){
			password = hex_sha512(data + hex_sha512(password));
			$.post("/login/doLogin", {"method" : method, "username" : username, "password" : password}, function(data){
				if (data == "success"){
					$("#form_login .notify_all_error").hide();
					$("#form_login .notify_all_ok").css("display", "inline");
					$("#form_login .notify_all_ok").html("登录成功！");
					$("#form_login .notify_all_ok").fadeIn("fast");
					globalCtrl.updateUserLoginState();
				}  else if (data == "wrong username"){
					showError("错误的手机号/Fido卡号，请重新输入。");
					$("#form_login #button_signup").attr("href", "javascript:submit()");
				}  else if (data == "wrong password"){
					showError("错误的密码，请重新输入。");
					$("#form_login #button_signup").attr("href", "javascript:submit()");
				}  else {
					showError("登录失败。");
					$("#form_login #button_signup").attr("href", "javascript:submit()");
				}
			});
		});
	}
</script>
<div class="form" id="form_login">
	<form>
		<div class="notify_all_ok" style="display:none;"></div>
		<div class="notify_all_error" style="display:none;"></div>
		<fieldset id="fieldset_login">
			<legend>登录</legend>
			<div id="login_username">
				<select id="login_method" style="moz-border-radius:3px;border:1px solid #DDDDDD;width:80px;margin-left:70px; margin-right:6px;">
					<option value="mobile">手机号</option>
					<option value="fidocard">Fido卡号</option>
				</select>
				<input type="text" name="username" id="input_username"></input>
			</div>
			<div id="login_password">
				<label>密码</label>
				<input type="password" name="password" id="input_password"></input>
			</div>
		</fieldset>
		<div id="bottom_buttons">
			<a class="button" id="button_login" href="javascript:submit()"></a>
		</div>
	</form>
</div>
 
